//
//  QSWorkStationInterface.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/5/21.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSWorkStationInterface.h"
#import "QSRequestManager.h"

@implementation QSWorkStationInterface
/**
* @brief 获取全部的工作数据
*/
+ (void)getAllWorkListWithPageIndex:(NSInteger)pageIndex
                           andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSWorkStationDataModel *resultModel))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kWorkStationAllWorkList];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
//    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
//    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSWorkStationDataModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            model = [QSWorkStationDataModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

/**
* @brief 获取我的工作数据
*/
+ (void)getMyWorkListWithPageIndex:(NSInteger)pageIndex
                          andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSWorkStationDataModel *resultModel))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kWorkStationMyWorkList];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSWorkStationDataModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            model = [QSWorkStationDataModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
    
}

/**
* @brief 获取工作单详情
*/
+ (void)getMyWorkDetailsWithId:(NSString *)ewId
                          andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSWorkDetailsModel *resultModel))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kWorkStationWorkDetails];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:ewId forKey:@"ewId"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSWorkDetailsModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            model = [QSWorkDetailsModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

/**
* @brief 获取完成人员数据
 * @param ewId 工作id
 * @param adminName 人名（可用搜索）
*/
+ (void)getPersonListWithId:(NSString *)ewId
                  AdminName:(NSString *)adminName
                   andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSArray *modelArr))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kWorkStationWorkPersonsList];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:ewId forKey:@"ewId"];
    if (adminName) {
        [bodyDic setObject:adminName forKey:@"adminName"];
    }
    [QSRequestManager executeTokenReturnArrayGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSArray *responseArr) {
        NSMutableArray *modelArr = [NSMutableArray array];
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            for (NSDictionary *dic in responseArr) {
                QSWorkStationPersonModel *model = [QSWorkStationPersonModel mj_objectWithKeyValues:dic];
                [modelArr addObject:model];
            }
            block(rspStatusAndMessage, modelArr.copy);
        }
    }];
}
/**
* @brief 提交工作备注（完成工作）
 * @param ewId 工作id
 */
+ (void)postFinishWorkWithId:(NSString *)ewId
                    andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSString *finishStr))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kWorkStationWorkFinish];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:ewId forKey:@"ewId"];
    
    [QSRequestManager executeTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, (NSString *)responseDataDic);
        }
    }];
}

/**
* @brief 提交工作备注（完成工作）
 * @param ewId 工作id
 * @param ewFinishRemark 备注
*/
+ (void)postFinishWorkWithId:(NSString *)ewId
                  Remark:(NSString *)ewFinishRemark
                    andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSString *finishStr))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kWorkStationSubmitRemark];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:ewId forKey:@"ewId"];
    if (ewFinishRemark) {
        [bodyDic setObject:ewFinishRemark forKey:@"ewFinishRemark"];
    }
    
    [QSRequestManager executeTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, (NSString *)responseDataDic);
        }
    }];
}
@end
